//
//  NSArray+JSExt.m
//  CarService
//
//  Created by sixarm on 2018/4/16.
//  Copyright © 2018年 sixarm. All rights reserved.
//

#import "NSArray+JSExt.h"

@implementation NSArray (JSExt)

/** 安全取出数组中的元素,避免越界造成的崩溃 */
- (id) wj_objectSafeAtIndex:(NSUInteger)index{
    if (self.count > index){
        return [self objectAtIndex:index];
    }
    return nil;
}

- (NSArray *)wj_removeObject:(id)object{
    NSMutableArray *result = [self mutableCopy];
    [result removeObject:object];
    return result;
}

- (NSArray *)wj_removeFirstObject{
    if (self.count == 0) return self;
    return [self subarrayWithRange:NSMakeRange(1, self.count - 1)];
}

- (NSArray *)wj_removeLastObject{
    if (self.count == 0) return self;
    return [self subarrayWithRange:NSMakeRange(0, self.count - 1)];
}

- (NSArray *)wj_reverseObject{
    //    return [[self reverseObjectEnumerator] allObjects];
    
    NSMutableArray *resultArray = [NSMutableArray arrayWithArray:self];
    for (NSInteger min = 0, max = resultArray.count - 1; min < max; min++, max--) {
        id tmp = resultArray[min];
        resultArray[min] = resultArray[max];
        resultArray[max] = tmp;
    }
    return resultArray;
}
@end
